///\todo upgrade

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_ZZ_DETAIL_VECTOR_H_
#define _BUOLA_ZZ_DETAIL_VECTOR_H_

#include <buola/zz.h>
#include <array>

namespace buola { namespace zz { namespace detail {

template<typename tCont>
void clear_container(tCont &pCont)
{
    pCont.clear();
}

inline void clear_container(UUnused&)
{
}
    
template<typename tCont,typename tObj>
void push_back_into(tCont &pCont,tObj &&pObj)
{
    pCont.push_back(std::forward<tObj>(pObj));
}
    
template<typename tObj>
inline void push_back_into(UUnused&,tObj&&)
{
}

template<typename tType,std::size_t vCount>
inline tType &get_array_element(std::array<tType,vCount> &pArray,std::size_t i)
{
    return pArray[i];
}

inline UUnused &get_array_element(UUnused &pUnused,std::size_t /*i*/)
{
    return pUnused;
}

template<typename tType>
struct MVectorType
{
    typedef std::vector<tType> type;
};

template<>
struct MVectorType<UUnused>
{
    typedef UUnused type;
};

template<typename tType,std::size_t vSize>
struct MArrayType
{
    typedef std::array<tType,vSize> type;
};

template<std::size_t vSize>
struct MArrayType<UUnused,vSize>
{
    typedef UUnused type;
};

//for star and plus, when trying to know which type of object we must create, if it is a vector or unused, we should
//create depending on tContainer, otherwise, just create whatever the parser wants
template<typename tSub,typename tIt,typename tContainer>
struct MVectorElementType
{
    typedef typename tSub::template tAttribute<tIt>::tType type;
};

template<typename tSub,typename tIt,typename tElement>
struct MVectorElementType<tSub,tIt,std::vector<tElement>>
{
    typedef tElement type;
};

template<typename tSub,typename tIt>
struct MVectorElementType<tSub,tIt,UUnused>
{
    typedef UUnused type;
};

/*namespace detail*/ } /*namespace zz*/ } /*namespace buola*/ }

#endif
